/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.boot.redis.service.impl;

import cn.hutool.system.SystemUtil;
import com.iwindplus.boot.redis.domain.annotation.RedisRateLimiter;
import com.iwindplus.boot.redis.service.RateLimiterKeyResolver;
import java.util.LinkedList;
import org.aspectj.lang.JoinPoint;
import org.springframework.cache.interceptor.KeyGenerator;

/**
 * 限流Key解析器接口实现类（Server节点级别的限流Key解析器）.
 *
 * @author zengdegui
 * @since 2020/6/13
 */
public class ServerNodeRateLimiterKeyResolver implements RateLimiterKeyResolver {

    @Override
    public String resolver(JoinPoint joinPoint, KeyGenerator keyGenerator, RedisRateLimiter rateLimiter) {
        LinkedList<Object> list = new LinkedList<>();
        String serverNode = String.format("%s@%d", SystemUtil.getHostInfo().getAddress(), SystemUtil.getCurrentPID());
        list.add(serverNode);
        return UserRateLimiterKeyResolver.getKeyGeneratorStr(joinPoint, keyGenerator, rateLimiter, list);
    }

}